#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 1e4 + 5;

int n, m;
vector<int> ch[N];
int dp[N][10];
void dfs(int u, int fu) {
  rep(i, 1, 9) dp[u][i] = i;
  for (int v : ch[u]) {
    if (v == fu) continue;
    dfs(v, u);
    rep(i, 1, 9) {
      int mn = 1e5;
      rep(j, 1, 9) if (j != i) mn = min(mn, dp[v][j]);
      dp[u][i] += mn;
    }
  }
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  rep(i, 2, n) {
    int u, v;
    cin >> u >> v;
    ch[u].push_back(v);
    ch[v].push_back(u);
  }
  dfs(1, 1);
  int ans = n * 10;
  rep(i, 1, 9) ans = min(ans, dp[1][i]);
  cout << ans;
  return 0;
}